package my.jieh.tips.swing;

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

public class SpinDemo1 {
  public static void main(String args[]) {
    // create a JFrame

    JFrame frame = new JFrame("SpinDemo1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a JSpinner with a range of
    // values 1-5 and starting value 1
    // and increment 1

    final SpinnerModel sm = new SpinnerNumberModel(2, -10, 10, 2);
    JSpinner jsp = new JSpinner(sm);

    // add a change listener

    jsp.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        System.out.println("changed: " + sm.getValue());
      }
    });

    // create a JComboBox

    Object list[] = {
        new Integer(1),
        new Integer(2), new Integer(3),
        new Integer(4), new Integer(5)};
    JComboBox jcb = new JComboBox(list);
    jcb.setEditable(true);

    // create a JPanel

    JPanel panel = new JPanel();
    panel.setPreferredSize(new Dimension(300, 300));
    panel.add(jsp);
    panel.add(jcb);
    frame.getContentPane().add(panel);

    // display the frame

    frame.pack();
    frame.setVisible(true);
  }

}// end class